import global from "./global.js"

	
const file = (e, params) => {
	let obj = params?params:{}
	return new Promise((resolve, reject) => {
		uni.uploadFile({
			header: { "Authorization":uni.getStorageSync('TZ_token') ?  'bearer' + uni.getStorageSync('TZ_token') : null },
			url: global.baseUrl + '/home/upload',
			filePath: e,
			name: 'file',
			formData: {
				...obj
			},
			success: (res) => {
				if(res.statusCode >= 200 && res.statusCode <  400){
					resolve({code:200,data:JSON.parse(res.data)})
				}else{
					resolve({code:res.statusCode,data:res})
					uni.showToast({
						title: res.data.message,
						icon: 'none',
					});
				}
				// resolve(JSON.parse(res.data))
			},
			fail: err => {
				reject(err)
			}
		})
	})
}

export default file